for
for (
variable initialisation
;
conditional expression
;
modification of variable
)
Example:
#include <iostream.h>
int main()
{
for (int x=0; x<100; x++)
{
cout << x << endl;
}
return 0;
}
for ( int x=0;
x<100;
x++)
Comment to example:
The loop goes while x<100, and x increases by one every loop. Keep in mind that the loop condition checks the conditional statement before it loops again.
Consequently, when x equals 100 the loop breaks outputting x.